package com.zmht.beike.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;

import com.zmht.beike.core.BaseDAOImpl;
import com.zmht.beike.dao.StudentDAO;
import com.zmht.beike.po.StudentTwo;

public class StudentDAOImpl extends BaseDAOImpl implements StudentDAO {

	public List<StudentTwo> findByCriteria(StudentTwo stu, Integer index,
			Integer count) {
		Session session = this.getSession();
		Criteria c = session.createCriteria(StudentTwo.class);
		//ƥ������
		if(null!=stu.getSname()&&!"".equals(stu.getSname())){
			c.add(Restrictions.like("sname",stu.getSname(),MatchMode.ANYWHERE));
		}
		if(null!=stu.getBjclasstype()){
			c.createAlias("bjclasstype", "tn").add(Restrictions.like("tn.typeName",stu.getBjclasstype().getTypeName(),MatchMode.ANYWHERE));
			//c.add(Restrictions.like("bjclasstype.typeName",stu.getBjclasstype().getTypeName(),MatchMode.ANYWHERE));//bjclasstype
		}
		
		c.setFirstResult(index*count);
		c.setMaxResults(count);
		return c.list();
	}
	/**
	 * ��ѯ��¼��
	 */
	public int findByCriteriaTotal(StudentTwo stu, Integer index,
			Integer count) {
		Session session = this.getSession();
		Criteria c = session.createCriteria(StudentTwo.class);
		//ƥ������
		if(null!=stu.getSname()&&!"".equals(stu.getSname())){
			c.add(Restrictions.like("sname",stu.getSname(),MatchMode.ANYWHERE));
		}
		if(null!=stu.getBjclasstype()){
			//c.add(Restrictions.like("bjclasstype.typeName",stu.getBjclasstype().getTypeName(),MatchMode.ANYWHERE));//bjclasstype
			c.createAlias("bjclasstype", "tn").add(Restrictions.like("tn.typeName",stu.getBjclasstype().getTypeName(),MatchMode.ANYWHERE));
			
		}
		
		//c.setFirstResult(index*count);
		//c.setMaxResults(count);
		return c.list().size();

	}

}
